#include "speedwgt.h"
#include <QPainter>
#include <QtSvg/QSvgRenderer>
#include  <QGraphicsOpacityEffect>
#include <QLabel>
#include <QBoxLayout>
SpeedWgt::SpeedWgt(QWidget*parent):QWidget(parent)
{
    this->resize(1110,500);

    QLabel *label =new QLabel(this);
    label->setStyleSheet("QLabel{background-image:url(':resources/images/SPEED.png') ;background-repeat:no-repeat;}");
    label->move(0,0);
    label->setFixedSize(this->width()*0.649, height()*0.13);

    QLabel *label1 =new QLabel(this);
    label1->setStyleSheet("QLabel{background-image:url(':resources/images/meter.png') ;background-repeat:no-repeat;}");
    label1->move(this->width()*0.002, this->height()*0.11);
    label1->setFixedSize(width()*0.996, height()*0.9);
}


void SpeedWgt::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

//    QPixmap pixmap(":/resources/images/SPEED.png");
//    painter.drawPixmap(0, 0, this->width()*0.649, height()*0.15, pixmap);
  //  QPixmap pixmap0(":/resources/images/meter.png");
  //  painter.drawPixmap(this->width()*0.002, this->height()*0.11, width()*0.996, height()*0.88, pixmap0);

    QPixmap pixmap1(":/resources/images/points.png");
    int pixmapWidth = pixmap1.width();
    int pixmapHeight = pixmap1.height();
    int rotationAngle = angle1; // 旋转角度，以度为单位
    double centerX = this->width() * 0.2 + pixmapWidth / 2; // 图片左下角X坐标 + 图片宽度的一半
    double centerY = this->height() * 0.25+ pixmapHeight*0.74;
    painter.translate(centerX, centerY); // 将旋转中心平移到图片底边中心
    painter.rotate(rotationAngle); // 以底边中心为圆心旋转图片
    painter.translate(-centerX, -centerY); // 将旋转中心还原回原始位置
    painter.setRenderHint(QPainter::Antialiasing);
    painter.drawPixmap(this->width() * 0.2 ,this->height() * 0.25,this->width() * 0.1 ,this->height() * 0.3, pixmap1);
    painter.end();

    painter.begin(this);
    QPixmap pixmap2(":/resources/images/points.png");
    int pixmapWidth1 = pixmap2.width();
    int pixmapHeight1 = pixmap2.height();
    double Angle1 =angle2; // 旋转角度，以度为单位
    double centerX1 = this->width() * 0.72 + pixmapWidth1 / 2;  // 旋转中心的X坐标
    double centerY1 = this->height() * 0.25+ pixmapHeight1 * 0.74;// 旋转中心的Y坐标
    painter.translate(centerX1, centerY1); // 将旋转中心平移到图片中心
    painter.rotate(Angle1); // 以旋转中心旋转图片
    painter.translate(-centerX1, -centerY1); // 将旋转中心还原回原始位置

    painter.drawPixmap(this->width() * 0.72, this->height() * 0.25,this->width() * 0.1 ,this->height() * 0.3, pixmap2);

}
void SpeedWgt::setRevolveAngle()
{
    angle1 =angle1 +1;
    this->update();
}

void SpeedWgt::setAdvanceAngle()
{
    angle2 =angle2 +1;
    this->update();
}
